package com.leetcode.partition6;

import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2021/10/20 12:29
 */
public class LC567字符串的排列 {

    public static boolean checkInclusion(String s1, String s2) {
        char[] ss1 = s1.toCharArray();
        Arrays.sort(ss1);
        //窗口 [left, right)
        for (int left = 0, right = s1.length(); right <= s2.length(); left++, right++) {
            char[] temp = s2.substring(left, right).toCharArray();
            Arrays.sort(temp);
            if (completeEquals(ss1, temp)) {
                return true;
            }
        }
        return false;
    }

    private static boolean completeEquals(char[] s1, char[] s2) {
        if (s1.length != s2.length) return false;
        for (int i = 0; i < s1.length; i++) {
            if (s1[i] == s2[i]) continue;
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        String s1 = "cba";
        String s2 = "eidboaoo";
        System.out.println(checkInclusion(s1, s2));
    }
}
